define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'user/member/index',
					add_url: 'user/member/add',
					edit_url: 'user/member/edit',
					// del_url: 'user/member/del',
                    import_url: 'user/member/import',
                    multi_url: 'user/member/multi',
                    table: 'member',
                }
            });

            var table = $("#table");
            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                            {field: 'id', title: __('Id'), sortable: true},
                            {field: 'username', title: __('用户名'), operate: false},
                            {field: 'mobile', title: __('Mobile'), operate: 'LIKE'},
							{field: 'createtime', title: __('Createtime'), formatter: Table.api.formatter.datetime,operate:false},
                            // {field: 'joinip', title: __('Joinip'), formatter: Table.api.formatter.search,operate:false},
                            {field: 'status', title: __('Status'), formatter: Table.api.formatter.status, searchList: {1: __('Normal'), 0: __('Hidden')},operate:false},
							// {field: 'type', title: __('Type'), formatter: Table.api.formatter.type, searchList: {1: '普通员工', 2: '集成员工'},operate:false},
							{field: 'type', title: __('员工类型'), searchList:{"1":__('普通员工'),"2":__('集成员工')},formatter: Table.api.formatter.normal},
							{field: 'integral', title: __('积分'),operate:false},
                            {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ],
				//禁用默认搜索
				search: false,
				//启用普通表单搜索
				commonSearch: true,
				//可以控制是否默认显示搜索单表,false则隐藏,默认为false
				searchFormVisible: true,
				showSearch: false,
            });
			$(document).on('click','.spec_add_btn', function (event) {
				var url = $(this).attr('data-url');
				if(!url) return false;
				var msg = $(this).attr('data-title');
				var width = $(this).attr('data-width');
				var height = $(this).attr('data-height');
				var area = [$(window).width() > 800 ? (width?width:'800px') : '95%', $(window).height() > 600 ? (height?height:'600px') : '95%'];
				var options = {
					shadeClose: false,
					shade: [0.3, '#393D49'],
					area: area,
					callback:function(value){
						CallBackFun(value.id, value.name);//在回调函数里可以调用你的业务代码实现前端的各种逻辑和效果
					}
				};
				Fast.api.open(url,msg,options);
			});
            // 为表格绑定事件
            Table.api.bindevent(table);
        },
		add: function () {
		    Controller.api.bindevent();
		    lonlat('','');
		},
		edit: function () {
		    Controller.api.bindevent();
		    var str = $("#c-lonlat").val();
		    var arr = str.split(',');
		    lonlat(arr[0],arr[1]);
		},
        reset: function(){
            $(document).on('click','.btn-success',function(){
                Form.api.submit($("form[role=form]"),function(){
                    window.parent.location.reload();
                })
            });
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        },
		
    };
    return Controller;
});
$(document).on("click", ".grant", function(){
    $.post({
        url: 'user/member/grant',
        type: 'POST',
        dataType: 'json',
        // data: {id: id},
        cache: false,
        success: function (ret) {
            if(ret.code == 1){
                Toastr.success('发放成功');
                window.setTimeout(function () {
                    window.location.reload();
                }, 3000);
            }else{
                Toastr.error('发放失败');
            }
        }, error: function () {
            Toastr.error(__('Network error'));
        }
    });
});

